package m.framework.controller;
import m.framework.exception.Message;
import m.framework.test.TestUtil;
import m.permission.controller.FrameController;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author ming
 * @date 2014年2月19日下午6:29:06
 */
public class ControllerMethodTest extends TestUtil{
	private static Logger log = LoggerFactory.getLogger(ControllerMethodTest.class);

	@Test
	public void testViewName() {
		ControllerMethod c=new ControllerMethod(new FrameController(), "index");
		assertThat(c.viewName(null), eq("/permission/frame/index"));
	}
	
	@Test
	public void testViewName包含forward() {
		ControllerMethod c=new ControllerMethod(new FrameController(), "index");
		assertThat(c.viewName("otherPage"), eq("/permission/frame/otherPage"));
	}
	
	@Test
	public void createView正常情况(){
		ControllerMethod c=new ControllerMethod(new FrameController(), "index");
		ModelAndView view=c.createView(null,null);
		assertThat(view.getViewName(), eq("/permission/frame/index"));
	}
	
	@Test
	public void createView执行异常(){
		ControllerMethod c=new ControllerMethod(new FrameController(), "index");
		ModelAndView view=c.createView(new Exception(),null);
		assertThat(view.getViewName(), eq(ControllerMethod.ERROR_PAGE));
		
		view=c.createView(new Message("错误信息"),null);
		assertThat(view.getViewName(), eq(ControllerMethod.MESSAGE_PAGE));
	}
}




